##Renewable Energy Dataset
library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(ggthemes)
energy<-read_csv('../../data/IRENA data.csv', skip=1)
## Rows: 67200 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Country/area, Technology, Data Type, Grid connection, Electricity s...
## dbl (1): Year
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
energy_2<-energy%>%
rename(country='Country/area')
high_gdp<-c("United States","Qatar","Norway","Singapore","United Arab Emirates",
"Switzerland","Ireland","Luxembourg","Saudi Arabia","Taiwan")
low_gdp<-c("Burundi","Central Africa Republic","Liberia","Democratic Republic of Congo",
"Mozambique","Niger","Madagascar","Malwai","Chad","Afghanistan")
energy_2$`Electricity statistics`<-
as.numeric(gsub("-",NA,energy_2$`Electricity statistics`))
world<-energy_2%>%
group_by(Technology,`Data Type`,`Grid connection`,Year)%>%
summarise(`Electricity statistics`=sum(`Electricity statistics`,na.rm=TRUE),
.groups="drop")%>%
mutate('country'="World")
energy_2<-bind_rows(energy_2,world)
energy_groups<-energy_2%>%
mutate(group=case_when(
country=="World"~"World",
country%in%high_gdp~"High GDP",
country %in%low_gdp~"Low GDP",
TRUE~NA_character_))%>%
filter(!is.na(group))
energy_groups_sdg<-energy_groups%>%
filter(Year%in% c(2012,2023))
energy_groups_sdg<-energy_groups_sdg%>%
group_by(group,Year,Technology)%>%
summarise(total=sum(`Electricity statistics`, na.rm=TRUE),
.groups="drop")
energy_groups_no_total<-energy_groups_sdg%>%
filter(!Technology%in%c("Total renewable","Total non-renewable","Total"))
energy_graph<-ggplot(energy_groups_no_total,
aes(x=group,
y=total,
fill=Technology))+
geom_col(position="fill",size=0.01)+
scale_y_continuous(labels=scales::percent)+
facet_wrap(~Year)+
coord_flip()+
labs(title="Energy Breakdown for Developed and Developing Countries",
x="Development Status of Countries",
y="Percent of Energy Type")+
theme_dark()
## Warning in geom_col(position = "fill", size = 0.01): Ignoring unknown
## parameters: `size`
ggplotly(energy_graph)
library(gapminder)
library(dplyr)
library(ggplot2)
data(gapminder)
gapminder%>%head
## # A tibble: 6 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Afghanistan Asia 1957 30.3 9240934 821.
## 3 Afghanistan Asia 1962 32.0 10267083 853.
## 4 Afghanistan Asia 1967 34.0 11537966 836.
## 5 Afghanistan Asia 1972 36.1 13079460 740.
## 6 Afghanistan Asia 1977 38.4 14880372 786.
gap<-gapminder%>%
filter(country %in% c('United States', 'China', 'France','Liberia','Ethiopia','Haiti'))%>%
filter(year>1970) %>%
mutate(status = ifelse(country %in% c('United States', 'China', 'France'), 'Developed', 'Developing'))
ggplot(gap,
aes(x=year,
y=lifeExp,
color=country,
linetype=status)) +
geom_line(size=1, alpha=0.5)+
#scale_linetype_manual(values=c("China"="solid","France"="solid","United States"="solid",
# "Ethiopia"="dashed","Haiti"="dashed","Liberia"="dashed")) +
labs(title = "Life Expectancy for Developed and Undeveloped Countries Over Time",
x = "Year",
y = "Life Expectancy")+
theme_clean()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
##Carbon emmissions
library(dplyr)
library(readr)
library(ggplot2)
library(plotly)
library(ggthemes)
url <-'https://nyc3.digitaloceanspaces.com/owid-public/data/co2/owid-co2-data.csv'
carbon <-
read_csv(url)
## Rows: 50191 Columns: 79
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): country, iso_code
## dbl (77): year, population, gdp, cement_co2, cement_co2_per_capita, co2, co2...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
carbon<-carbon%>%
mutate(gdp_per_capita=gdp/population)
high_gdp<-c("United States","Qatar","Norway","Singapore","United Arab Emirates",
"Switzerland","Ireland","Luxembourg","Saudi Arabia","Taiwan")
low_gdp<-c("Burundi","Central Africa Republic","Liberia","Democratic Republic of Congo",
"Mozambique","Niger","Madagascar","Malwai","Chad","Afghanistan")
carbon_groups<-carbon%>%
mutate(group=case_when(
country=="World"~"World",
country%in%high_gdp~"High GDP",
country %in%low_gdp~"Low GDP",
TRUE~NA_character_))%>%
filter(!is.na(group))
carbon_wo_world<-carbon%>%
filter(country!="World")
carbon_groups<-carbon_wo_world%>%
mutate(group=case_when(
country%in%high_gdp~"High GDP",
country%in%low_gdp~"Low GDP",
TRUE~"World"))
carbon_trend<-carbon_groups%>%
group_by(year,group)%>%
summarise(mean_temp=mean(temperature_change_from_ghg, na.rm=TRUE),
.groups="drop")
plot_1<-ggplot(carbon_trend,
aes(x=year,y=mean_temp,color=group))+
geom_line(size=1)+
geom_vline(xintercept=2012,
linetype ="dashed",
size=0.5)+
scale_x_continuous(limits=c(1850,max(carbon_trend$year)))+
labs(title="Average Temperature Change from Greenhouse Gas Emmissions",
x="Year",
y="Temperature Change",
color="Key")+
labs(title="Average emperature Change from Greenhouse Gas Emmissions",
x="Temperature Change from Gas Emmissions",
y="Development of Countries")+
annotate(geom='text',
x=1985,
y=.005,
size=3,
label='Year when SDGs
were created')+
theme_minimal()
#TEMP CHANGE FROM GHGS
library(dplyr)
library(readr)
library(ggplot2)
library(plotly)
library(ggthemes)
url <-'https://nyc3.digitaloceanspaces.com/owid-public/data/co2/owid-co2-data.csv'
carbon <-
read_csv(url)
## Rows: 50191 Columns: 79
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): country, iso_code
## dbl (77): year, population, gdp, cement_co2, cement_co2_per_capita, co2, co2...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
carbon_groups<-carbon%>%
mutate(group=case_when(
country=="World"~"World",
country%in%high_gdp~"High GDP",
country %in%low_gdp~"Low GDP",
TRUE~NA_character_))%>%
filter(!is.na(group))
high_gdp<-c("United States","Qatar","Norway","Singapore","United Arab Emirates",
"Switzerland","Ireland","Luxembourg","Saudi Arabia","Taiwan")
low_gdp<-c("Burundi","Central Africa Republic","Liberia","Democratic Republic of Congo",
"Mozambique","Niger","Madagascar","Malwai","Chad","Afghanistan")
carbon_wo_world<-carbon%>%
filter(country!="World")
carbon_groups<-carbon_wo_world%>%
mutate(group=case_when(
country%in%high_gdp~"High GDP",
country%in%low_gdp~"Low GDP",
TRUE~"World"))
carbon_trend<-carbon_groups%>%
group_by(year,group)%>%
summarise(mean_temp=mean(temperature_change_from_ghg, na.rm=TRUE),
.groups="drop")
plot_2<-ggplot(carbon_trend,
aes(x=year,y=mean_temp,color=group))+
geom_line(size=1)+
geom_vline(xintercept=2012,
linetype ="dashed",
size=0.5)+
scale_x_continuous(limits=c(2000,max(carbon_trend$year)))+
labs(title="Average Temperature Change from Greenhouse Gas Emmissions",
x="Year",
y="Temperature Change",
color="Key")+
annotate(geom='text',
x=2008,
y=0.005,
size=3,
label='Year when SDGs
were created')+
theme_minimal()
library(ggpubr)
ggarrange(plot_1,plot_2,nrow=1)+
labs(title="Average Temperature Change from Greenhouse Gases from Developed and Developing Countries")
## Warning: Removed 303 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Warning: Removed 750 rows containing missing values or values outside the scale range
## (`geom_line()`).
##Levelized cost of energy
library(readr)
url <- 'https://raw.githubusercontent.com/ericmkeen/sewanee_esus/master/02_energy_sector/levelized-cost-of-energy.csv'
econ <- read_csv(url)
## Rows: 3402 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): country, source
## dbl (2): year, cost
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
econ%>%head
## # A tibble: 6 × 4
## country year source cost
## <chr> <dbl> <chr> <dbl>
## 1 Australia 2010 Bioenergy NA
## 2 Australia 2010 Geothermal NA
## 3 Australia 2010 Offshore wind NA
## 4 Australia 2010 Solar photovoltaic 0.424
## 5 Australia 2010 Concentrated solar power NA
## 6 Australia 2010 Hydropower NA
library(ggplot2)
library(dplyr)
library(readr)
library(ggthemes)
url <- 'https://raw.githubusercontent.com/ericmkeen/sewanee_esus/master/02_energy_sector/levelized-cost-of-energy.csv'
econ <- read_csv(url)
## Rows: 3402 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): country, source
## dbl (2): year, cost
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#cost of renewable and non-renewable sources
econ_filtered<-econ%>%
filter(country%in% c("United States","France","Sweden","Germany","Japan","China","South Korea","United Kingdom","Netherlands","Denmark"))
p<-ggplot(econ_filtered,
aes(x=year,
y=cost,
color=factor(source),
text=paste("country:",country,
"<br>year:",year,
"<br>source:",source,
"<br>cost:",round(cost,2))))+
geom_point()+
geom_vline(xintercept=2012)+
labs(title="Cost and Use of Energy Types for Developed Countries",
x="Year",
y="Cost",
color="Energy Source")
annotate(geom='text',
x=2003,y=0.52,
size=3,
label='Year when SDGs were created')
## mapping: x = ~x, y = ~y
## geom_text: na.rm = FALSE
## stat_identity: na.rm = FALSE
## position_identity
ggplotly(p,tooltip="text")
library(dplyr)
library(knitr)
econ_filtered<-econ%>%
filter(country%in% c("United States","France","Sweden","Germany","Japan","China","South Korea","United Kingdom","Netherlands","Denmark"))
econ_filtered%>%
group_by(year,country)%>%
summarize(cost=mean(cost, na.rm=TRUE))%>%
kable
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
| year | country | cost |
|---|---|---|
| 1984 | Denmark | 0.2371748 |
| 1984 | Germany | 0.2529806 |
| 1984 | Sweden | 0.2523369 |
| 1984 | United States | 0.3238081 |
| 1985 | Denmark | 0.2223528 |
| 1985 | United States | 0.3044088 |
| 1986 | Denmark | 0.2154760 |
| 1986 | United States | 0.2752370 |
| 1987 | Denmark | 0.2056009 |
| 1987 | United States | 0.2694026 |
| 1988 | Denmark | 0.2155145 |
| 1988 | United States | 0.2100088 |
| 1989 | Denmark | 0.1964690 |
| 1989 | United Kingdom | 0.2041509 |
| 1989 | United States | 0.1960202 |
| 1990 | Denmark | 0.1971670 |
| 1990 | Germany | 0.2203359 |
| 1990 | Sweden | 0.2197228 |
| 1990 | United Kingdom | 0.2050081 |
| 1990 | United States | 0.2162832 |
| 1991 | Denmark | 0.1865857 |
| 1991 | France | 0.2035929 |
| 1991 | Germany | 0.2086170 |
| 1991 | Sweden | 0.2080319 |
| 1991 | United Kingdom | 0.1939899 |
| 1991 | United States | 0.2098921 |
| 1992 | Denmark | 0.1832888 |
| 1992 | Germany | 0.2268206 |
| 1992 | Sweden | 0.2261551 |
| 1992 | United Kingdom | 0.2084716 |
| 1993 | Denmark | 0.1841186 |
| 1993 | France | 0.2163642 |
| 1993 | Germany | 0.2220791 |
| 1993 | Sweden | 0.2214135 |
| 1993 | United Kingdom | 0.1912740 |
| 1994 | Germany | 0.1677483 |
| 1994 | Sweden | 0.2090198 |
| 1994 | United Kingdom | 0.1930470 |
| 1995 | Denmark | 0.1532715 |
| 1995 | Germany | 0.2061206 |
| 1995 | Sweden | 0.1985365 |
| 1995 | United Kingdom | 0.1825638 |
| 1996 | China | 0.1816425 |
| 1996 | Denmark | 0.1493380 |
| 1996 | France | 0.1986796 |
| 1996 | Germany | 0.1894378 |
| 1996 | Sweden | 0.2039947 |
| 1996 | United Kingdom | 0.1871813 |
| 1997 | China | 0.1816425 |
| 1997 | Denmark | 0.1534140 |
| 1997 | France | 0.1849604 |
| 1997 | Germany | 0.1882095 |
| 1997 | Sweden | 0.1900097 |
| 1997 | United Kingdom | 0.1740369 |
| 1998 | China | 0.1667260 |
| 1998 | Denmark | 0.1565765 |
| 1998 | France | 0.1830855 |
| 1998 | Germany | 0.1752856 |
| 1998 | Sweden | 0.1881348 |
| 1998 | United Kingdom | 0.1721621 |
| 1998 | United States | 0.1205701 |
| 1999 | China | 0.1632182 |
| 1999 | Denmark | 0.1537264 |
| 1999 | France | 0.1754731 |
| 1999 | Germany | 0.1868320 |
| 1999 | Sweden | 0.1805224 |
| 1999 | United Kingdom | 0.1645496 |
| 1999 | United States | 0.1161334 |
| 2000 | China | 0.1492229 |
| 2000 | Denmark | 0.1673548 |
| 2000 | France | 0.1398779 |
| 2000 | Germany | 0.1841436 |
| 2000 | Japan | 0.1686539 |
| 2000 | United Kingdom | 0.1131557 |
| 2000 | United States | 0.1013885 |
| 2001 | China | 0.1246857 |
| 2001 | Denmark | 0.1613982 |
| 2001 | France | 0.1418427 |
| 2001 | Germany | 0.1922390 |
| 2001 | Sweden | 0.1462334 |
| 2001 | United Kingdom | 0.1283265 |
| 2001 | United States | 0.0953408 |
| 2002 | China | 0.1404714 |
| 2002 | Denmark | 0.1185489 |
| 2002 | France | 0.1469024 |
| 2002 | Germany | 0.1531272 |
| 2002 | Sweden | 0.1673399 |
| 2002 | United Kingdom | 0.1338465 |
| 2002 | United States | 0.0902251 |
| 2003 | China | 0.0986673 |
| 2003 | Denmark | 0.0951942 |
| 2003 | France | 0.1138065 |
| 2003 | Germany | 0.1398898 |
| 2003 | Sweden | 0.1296701 |
| 2003 | United Kingdom | 0.1336529 |
| 2003 | United States | 0.0801150 |
| 2004 | China | 0.1041320 |
| 2004 | Denmark | 0.0849089 |
| 2004 | France | 0.1279492 |
| 2004 | Germany | 0.1399999 |
| 2004 | Sweden | 0.1406168 |
| 2004 | United Kingdom | 0.1402979 |
| 2004 | United States | 0.0882453 |
| 2005 | China | 0.1020668 |
| 2005 | Denmark | 0.0995617 |
| 2005 | France | 0.1264183 |
| 2005 | Germany | 0.1449175 |
| 2005 | Japan | 0.1668268 |
| 2005 | Sweden | 0.1455130 |
| 2005 | United Kingdom | 0.1326896 |
| 2005 | United States | 0.0780249 |
| 2006 | China | 0.0969125 |
| 2006 | Denmark | 0.1232860 |
| 2006 | France | 0.1272836 |
| 2006 | Germany | 0.1491074 |
| 2006 | Sweden | 0.1455130 |
| 2006 | United Kingdom | 0.1331456 |
| 2006 | United States | 0.0881904 |
| 2007 | China | 0.0849595 |
| 2007 | France | 0.1198520 |
| 2007 | Germany | 0.1370723 |
| 2007 | Sweden | 0.1317984 |
| 2007 | United Kingdom | 0.1263473 |
| 2007 | United States | 0.0868338 |
| 2008 | China | 0.0898723 |
| 2008 | Denmark | 0.1187360 |
| 2008 | France | 0.1600386 |
| 2008 | Germany | 0.1644760 |
| 2008 | Sweden | 0.1491739 |
| 2008 | United Kingdom | 0.1387804 |
| 2008 | United States | 0.0988465 |
| 2009 | China | 0.0909917 |
| 2009 | France | 0.1321602 |
| 2009 | Germany | 0.1519318 |
| 2009 | Sweden | 0.1436692 |
| 2009 | United Kingdom | 0.0767546 |
| 2009 | United States | 0.1102728 |
| 2010 | China | 0.1956353 |
| 2010 | Denmark | 0.1196706 |
| 2010 | France | 0.2653962 |
| 2010 | Germany | 0.2593413 |
| 2010 | Japan | 0.1702264 |
| 2010 | South Korea | 0.4509997 |
| 2010 | Sweden | 0.1145101 |
| 2010 | United Kingdom | 0.3181708 |
| 2010 | United States | 0.1616822 |
| 2011 | China | 0.1739857 |
| 2011 | Denmark | 0.1168540 |
| 2011 | France | 0.2606771 |
| 2011 | Germany | 0.2273566 |
| 2011 | Japan | 0.2934478 |
| 2011 | South Korea | 0.4721218 |
| 2011 | Sweden | 0.1090732 |
| 2011 | United Kingdom | 0.2988785 |
| 2011 | United States | 0.1855998 |
| 2012 | China | 0.1374451 |
| 2012 | Denmark | 0.0910542 |
| 2012 | France | 0.2576304 |
| 2012 | Germany | 0.1893619 |
| 2012 | Japan | 0.2495644 |
| 2012 | South Korea | 0.1905774 |
| 2012 | Sweden | 0.1054622 |
| 2012 | United Kingdom | 0.1918472 |
| 2012 | United States | 0.1596206 |
| 2013 | China | 0.1138426 |
| 2013 | Denmark | 0.0889607 |
| 2013 | France | 0.1697370 |
| 2013 | Germany | 0.1585732 |
| 2013 | Japan | 0.2130375 |
| 2013 | South Korea | 0.2252698 |
| 2013 | Sweden | 0.0839654 |
| 2013 | United Kingdom | 0.1639955 |
| 2013 | United States | 0.1511638 |
| 2014 | China | 0.0921410 |
| 2014 | France | 0.1251846 |
| 2014 | Germany | 0.1258181 |
| 2014 | Japan | 0.1928266 |
| 2014 | South Korea | 0.1736466 |
| 2014 | Sweden | 0.0909544 |
| 2014 | United Kingdom | 0.1401094 |
| 2014 | United States | 0.1088508 |
| 2015 | China | 0.0749064 |
| 2015 | Denmark | 0.0633129 |
| 2015 | France | 0.0983155 |
| 2015 | Germany | 0.1055222 |
| 2015 | Japan | 0.1466564 |
| 2015 | South Korea | 0.1596109 |
| 2015 | Sweden | 0.0737552 |
| 2015 | United Kingdom | 0.1150627 |
| 2015 | United States | 0.1001385 |
| 2016 | China | 0.0667813 |
| 2016 | Denmark | 0.0554282 |
| 2016 | France | 0.0828116 |
| 2016 | Germany | 0.0937066 |
| 2016 | Japan | 0.1722541 |
| 2016 | Netherlands | 0.1193991 |
| 2016 | South Korea | 0.1529640 |
| 2016 | Sweden | 0.0631350 |
| 2016 | United Kingdom | 0.1056802 |
| 2016 | United States | 0.0913045 |
| 2017 | China | 0.0559165 |
| 2017 | Denmark | 0.0457878 |
| 2017 | France | 0.0817822 |
| 2017 | Germany | 0.0878803 |
| 2017 | Japan | 0.1285732 |
| 2017 | Netherlands | 0.1328713 |
| 2017 | South Korea | 0.1031784 |
| 2017 | Sweden | 0.0568471 |
| 2017 | United Kingdom | 0.0912089 |
| 2017 | United States | 0.0703899 |
| 2018 | China | 0.0493549 |
| 2018 | Denmark | 0.0437401 |
| 2018 | France | 0.0663755 |
| 2018 | Germany | 0.0796272 |
| 2018 | Japan | 0.1318241 |
| 2018 | Netherlands | 0.1012457 |
| 2018 | South Korea | 0.0850538 |
| 2018 | Sweden | 0.0423804 |
| 2018 | United Kingdom | 0.0822094 |
| 2018 | United States | 0.0580212 |
| 2019 | China | 0.0421479 |
| 2019 | Denmark | 0.0453368 |
| 2019 | France | 0.0578050 |
| 2019 | Germany | 0.0656348 |
| 2019 | Japan | 0.1167038 |
| 2019 | Netherlands | 0.0966343 |
| 2019 | South Korea | 0.0781410 |
| 2019 | Sweden | 0.0405149 |
| 2019 | United Kingdom | 0.0723098 |
| 2019 | United States | 0.0501545 |
| 2020 | China | 0.0372340 |
| 2020 | Denmark | 0.0399788 |
| 2020 | France | 0.0510864 |
| 2020 | Germany | 0.0563428 |
| 2020 | Japan | 0.1057996 |
| 2020 | Netherlands | 0.0912981 |
| 2020 | South Korea | 0.0596249 |
| 2020 | Sweden | 0.0386235 |
| 2020 | United Kingdom | 0.0602736 |
| 2020 | United States | 0.0471003 |
| 2021 | China | 0.0311026 |
| 2021 | France | 0.0464205 |
| 2021 | Germany | 0.0559515 |
| 2021 | Japan | 0.1135182 |
| 2021 | Netherlands | 0.0781061 |
| 2021 | South Korea | 0.0557920 |
| 2021 | Sweden | 0.0363757 |
| 2021 | United Kingdom | 0.0555972 |
| 2021 | United States | 0.0424529 |